package com.ruoyi.business.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.business.domain.FileTransferOut;
import com.ruoyi.business.domain.bo.FileTransferOutBo;
import com.ruoyi.business.domain.vo.FileTransferOutVo;
import com.ruoyi.business.service.IFileTransferOutService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 档案转出
 *
 * @author sal
 * @date 2024-11-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/TransferOut")
public class FileTransferOutController extends BaseController {

    private final IFileTransferOutService iFileTransferOutService;

    /**
     * 查询档案转出列表
     */
    @SaCheckPermission("business:TransferOut:list")
    @GetMapping("/list")
    public TableDataInfo<FileTransferOutVo> list(FileTransferOutBo bo, PageQuery pageQuery) {
        return iFileTransferOutService.queryPageList(bo, pageQuery);
    }
    @SaCheckPermission("business:TransferOut:list")
    @GetMapping("/list1")
    public TableDataInfo<FileTransferOutVo> list1(FileTransferOutBo bo, PageQuery pageQuery) {
        return iFileTransferOutService.queryPageList1(bo, pageQuery);
    }

    /**
     * 导出档案转出列表
     */
    @SaCheckPermission("business:TransferOut:export")
    @Log(title = "档案转出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(FileTransferOutBo bo, HttpServletResponse response) {
        List<FileTransferOutVo> list = iFileTransferOutService.queryList(bo);
        ExcelUtil.exportExcel(list, "档案转出", FileTransferOutVo.class, response);
    }

    /**
     * 获取档案转出详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:TransferOut:query")
    @GetMapping("/{id}")
    public R<FileTransferOutVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iFileTransferOutService.queryById(id));
    }

    /**
     * 新增档案转出
     */
    @SaCheckPermission("business:TransferOut:add")
    @Log(title = "档案转出", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<FileTransferOut> add(@Validated(AddGroup.class) @RequestBody FileTransferOutBo bo) {
        return R.ok(iFileTransferOutService.insertByBo(bo));
    }

    /**
     * 修改档案转出
     */
    @SaCheckPermission("business:TransferOut:edit")
    @Log(title = "档案转出", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<FileTransferOut> edit(@Validated(EditGroup.class) @RequestBody FileTransferOutBo bo) {
        return R.ok(iFileTransferOutService.updateByBo(bo));
    }

    /**
     * 删除档案转出
     *
     * @param ids 主键串
     */
    @SaCheckPermission("business:TransferOut:remove")
    @Log(title = "档案转出", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iFileTransferOutService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
